<html>
<head>
  <title>Context Window</title>
  <script type="module">
    import { store } from "/components/modals/context/context-store.js";
  </script>
</head>
<body>
  <div x-data>
    <template x-if="$store.context">
      <div class="context-modal-root">
        
        <!-- Loading State -->
        <template x-if="$store.context.isLoading">
          <div class="loading-state">
            <div class="loading-spinner"></div>
            <p>Loading context window…</p>
          </div>
        </template>
        
        <!-- Error State -->
        <template x-if="$store.context.error">
          <div class="error-state">
            <p class="error-message" x-text="$store.context.error"></p>
          </div>
        </template>
        
        <!-- Content (ACE Editor) -->
        <template x-if="!$store.context.isLoading && !$store.context.error">
          <div id="context-viewer-container"></div>
        </template>
        
      </div>
    </template>
  </div>

  <style>
    .context-modal-root {
      display: flex;
      flex-direction: column;
      width: 100%;
      height: 100%;
      min-height: 400px;
    }

    .loading-state,
    .error-state {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: var(--spacing-lg);
      min-height: 200px;
    }

    .loading-spinner {
      width: 40px;
      height: 40px;
      border: 3px solid var(--color-border);
      border-top: 3px solid var(--color-primary);
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin-bottom: var(--spacing-md);
    }

    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }

    .loading-state p,
    .error-state p {
      color: var(--color-text-secondary);
      margin: 0;
    }

    .error-message {
      color: var(--color-error);
      font-weight: 500;
    }

    /* ACE Editor Container */
    #context-viewer-container {
      width: 100%;
      height: 71vh;
      border-radius: 0.4rem;
      overflow: auto;
    }

    #context-viewer-container::-webkit-scrollbar {
      width: 0;
    }

    /* ACE Editor Scrollbar */
    .ace_scrollbar-v {
      overflow-y: auto;
    }

    /* Viewer Styles */
    .context-modal-root {
      overflow: hidden;
    }
  </style>

</body>
</html>

